home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / level_update.lua < prev    next >
Encoding:
Text File  |  2005-07-16  |  2.3 KB  |  72 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- View update
  4. -- -----------------------------------------------------------------
  5. local function animateFish(model)
  6.     if model:isAlive() then
  7.         local action = model:getAction()
  8.  
  9.         if "move_up" == action then
  10.             model:runAnim("vertical_up")
  11.         elseif "move_down" == action then
  12.             model:runAnim("vertical_down")
  13.         elseif "move_left" == action or "move_right" == action then
  14.             model:runAnim("swam")
  15.         elseif "turn" == action then
  16.             model:runAnim("turn")
  17.         elseif "activate" == action then
  18.             model:setAnim("turn", 0)
  19.         elseif "busy" == action then
  20.             model:setAnim("turn", 0)
  21.         else
  22.             --NOTE: for talking see animateHead() bellow
  23.             model:runAnim("rest")
  24.         end
  25.     else
  26.         model:runAnim("skeleton")
  27.     end
  28. end
  29.  
  30. -- -----------------------------------------------------------------
  31. local function animateHead(model)
  32.     if model:isAlive() then
  33.         local state = model:getState()
  34.         if "talking" == state or model_isTalking(TALK_INDEX_BOTH) then
  35.             if not model.talk_phase then
  36.                 model.talk_phase = random(3)
  37.             elseif math.mod(game_getCycles(), 2) == 0 then
  38.                 model.talk_phase = math.mod(
  39.                     model.talk_phase + randint(1, 2), 3)
  40.             end
  41.         else
  42.             model.talk_phase = false
  43.         end
  44.  
  45.         local action = model:getAction()
  46.         if "busy" == action then
  47.             if model.talk_phase then
  48.                 model:setAnim("talk", model.talk_phase)
  49.             else
  50.                 model:setAnim("turn", 0)
  51.             end
  52.         else
  53.             if "talking" == state or model_isTalking(TALK_INDEX_BOTH) then
  54.                 model:useSpecialAnim("head_talking", model.talk_phase)
  55.             elseif "pushing" == state then
  56.                 model:useSpecialAnim("head_pushing", 0)
  57.             elseif random(100) < 6 then
  58.                 model:useSpecialAnim("head_blink", 0)
  59.             end
  60.         end
  61.     end
  62. end
  63.  
  64. -- -----------------------------------------------------------------
  65. function animateUnits()
  66.     for index, unit in pairs(getUnitTable()) do
  67.         animateFish(unit)
  68.         animateHead(unit)
  69.     end
  70. end
  71.  
  72.